{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import json\n",
    "oj = json.load(open('oj.json'))\n",
    "acmer = json.load(open('acm.json'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import requests\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "from scrapy import Selector"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "r = Selector(text=requests.get('http://acm.hdu.edu.cn/userstatus.php?user=wangkechun').text)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[u'621']"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "def hdu(name):\n",
    "    r = Selector(text=requests.get('http://acm.hdu.edu.cn/userstatus.php?user='+name).text)\n",
    "    ac = r.xpath('/html/body/table/tr[4]/td/table/tr/td/table[1]/tr[3]/td[2]/text()').extract()[0]\n",
    "    return ac\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "def hn(name):\n",
    "    r = Selector(text=requests.get('http://125.221.232.253/JudgeOnline/userinfo.php?user='+name).text)\n",
    "    ac = r.xpath('//*[@id=\"statics\"]/tr[2]/td[2]/a/text()').extract()[0]\n",
    "    return ac\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "u'16'"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "hdu('hnust_wangkechun')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "u'621'"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "hdu('wangkechun')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "u'98'"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "hn(\"hnust_wangkechun\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "def bnuoj(name):\n",
    "    name = name.replace('_','')\n",
    "    r = Selector(text=requests.get('http://www.bnuoj.com/v3/userinfo.php?name='+name).text)\n",
    "    ac = r.xpath('//*[@id=\"userinfo\"]/table/tr[9]/td/div[1]/text()').extract()[0]\n",
    "    return re.search('\\d+',ac).group()\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "bnuoj('hnustwangkechun')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "u'3'"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "def poj(name):\n",
    "    r = Selector(text=requests.get('http://poj.org/userstatus?user_id='+name).text)\n",
    "    ac = r.xpath('/html/body/center/table/tr[3]/td[2]/a/text()').extract()[0]\n",
    "    return ac\n",
    "poj('hnust_wangkechun')\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "u'17'"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "def acdream(name):\n",
    "    r = Selector(text=requests.get('http://acdream.info/user/'+name).text)\n",
    "    ac = r.xpath('//*[@id=\"xbody\"]/fieldset/div[2]/div[2]/ul/li[4]/span/text()').extract()[0]\n",
    "    return ac\n",
    "acdream('hnust_wangkechu')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "u'1403'"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "def cf(name):\n",
    "    r = Selector(text=requests.get('http://codeforces.com/profile/'+name).text)\n",
    "    ac = r.xpath('//*[@id=\"content\"]/div[2]/div[5]/div[2]/ul/li[1]/span[1]/text()').extract()[0]\n",
    "    return ac\n",
    "cf('hnust_wangkechun')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "u'2078'"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "def bestcoder(name):\n",
    "    r = Selector(text=requests.get('http://bestcoder.hdu.edu.cn/rating.php?user='+name).text)\n",
    "    ac = r.xpath('//*[@id=\"rating\"]/div[1]/div[4]/p[2]/text()').extract()[0]\n",
    "    return re.search('\\d+',ac).group()\n",
    "bestcoder('aslmaswd')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "u'10578.37'"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "def codechef(name):\n",
    "    r = Selector(text=requests.get('http://www.codechef.com/users/'+name).text)\n",
    "    ac = r.xpath('//*[@id=\"hp-sidebar-blurbRating\"]/div/table/tr[2]/td[3]/text()').extract()[0]\n",
    "    return ac\n",
    "codechef('zcy1zhy3')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
